import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import AutoImport from 'unplugin-auto-import/vite'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue', 'vue-router'],
    })
  ],
  server: {
    proxy: {
      '/hitokoto': {
        target: 'https://hitokoto.cn',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/hitokoto/, '')
      },
      '/api': {
        target: 'https://hitokoto.cn', // 目标地址 --> 服务器地址
        changeOrigin: true, // 是否跨域,允许跨域
        ws: true, // 是否启用websockets
        rewrite: path => path.replace(/^\/api/, '') // 重写路径
      }
    }
  },
  build: {
    // 解决: Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
    chunkSizeWarningLimit: 1500,
    rollupOptions: {
      output: {
        entryFileNames: `assets/[name].js`,
        chunkFileNames: `assets/[name].js`,
        assetFileNames: `assets/[name].[ext]`,
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        }
      },
    }
  }
})
